// https://leetcode.cn/problems/my-calendar-ii/
// Created by ade on 2022/7/19.
//
#include <iostream>
#include <vector>
#include <map>


using namespace std;

class MyCalendarTwo {
public:
    map<int, int> myMap;

    MyCalendarTwo() {
        myMap.insert({-1, -1});
    }

    // 暴力法超时
    bool book1(int start, int end) {
        for (int i = start; i < end; i++) {
            myMap[i]++;
            if (myMap[i] > 2) {
                for (int j = start; j <= i; j++) {
                    myMap[j]--;
                }
                return false;
            }
        }
        return true;
    }

    vector <pair<int, int>> booked;
    vector <pair<int, int>> overlaps;

    bool book(int start, int end) {
        for (auto &i : overlaps) {
            if (i.first < end && i.second > start) {
                return false;
            }
        }
        for (auto i : booked) {
            if (i.first < end && i.second > start) {
                overlaps.emplace_back(pair<int, int>{max(i.first, start), min(i.second, end)});
            }
        }
        booked.emplace_back(pair<int, int>{start, end});
        return true;
    }

};

int main() {
    MyCalendarTwo so;
    vector <pair<int, int>> res;
    res = {{26, 35},
           {26, 32},
           {34, 36},
           {18, 26},
           {40, 45},
           {19, 26},
           {48, 50},
           {1,  6},
           {46, 50},
           {11, 18}};
    for (auto i : res) {
        if (so.book(i.first, i.second)) {
            cout << "true," << endl;
        } else {
            cout << "false," << endl;
        }
    }
    return 0;

}



